{include file="publics/head"/}
<body class="no-skin">
{include file="publics/header"/}
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    {include file="publics/sidebar"/}
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            {include file="publics/breadcrumbs"/}

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                {include file="publics/set"/}

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
	                    <a class="btn btn-info" href="{:url('add')}" value="">新增</a>
	                    <div class="space-4"></div>
                        <!-- PAGE CONTENT BEGINS -->
                        <form id="export-form" method="post">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th class="center"><input class="check-all" type="checkbox" value=""></th>
                                    <th>用户组</th>
                                    <th>状态</th>
                                    <th class="center">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {volist name="list" id="val"}
                                    <tr>
                                        <td class="center">
                                            {if condition="$val['id'] neq 1"}<input class="ids" type="checkbox"
                                                                                    name="ids[]" value="{$val['id']}">
                                                {else/}
                                                <span title="系统用户组，禁止删除">--</span>{/if}

                                        </td>
                                        <td>{$val['title']}</td>
                                        <td>
                                            {if condition="$val['id'] eq 1 "} 启用
                                            {elseif  condition="$val['status'] eq 1" /}<a href="javascript:;" class="status" name="" val="{$val.id}" title="点击禁用">启用</a>
                                                {else /}
                                                <a href ="javascript:;" class="status" name="" val="{$val.id}"  title="点击启用">禁用</a>
                                            {/if}
                                        </td>
                                        <td class="center"><a href="{:url('edit',array('id'=>$val['id']))}">修改</a></td>
                                    </tr>
                                {/volist}
                                </tbody>
                            </table>
                            <div class="cf">
                                <input class="btn btn-info" id="submit" value="删除">
                            </div>
                        </form>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    {include file="publics/footer"/}

</div><!-- /.main-container -->

{include file="publics/footerjs"/}
<!-- inline scripts related to this page -->
<script type="text/javascript">
    (function ($) {
        $(".check-all").click(function () {
            $(".ids").prop("checked", this.checked);
        });
        $(".ids").click(function () {
            var option = $(".ids");
            option.each(function (i) {
                if (!this.checked) {
                    $(".check-all").prop("checked", false);
                    return false;
                } else {
                    $(".check-all").prop("checked", true);
                }
            });
        });
    })(jQuery);
   //修改状态
   $(".status").click(function(){
	   var group = $(this).attr('val');
	   $.ajax({
       	type:"post",
       	url:"{:url('status')}",
       	data:'id='+group,
       	//dataType:"",
       	error:function(){
       		return false;
       	},
       	success:function(data){
       		//alert(data.message);
       		bootbox.alert({  
                buttons: {  
                   ok: {label: '确定',className: 'btn-danger'}  
                },  
                message: data.message,  
                callback: function() {  
                    if(data.flag == 0){
                  	   location.reload(); 
                     }
                },  
                title: "系统提示",  
            });
       	}
       });
   });
  //批量删除
    $("#submit").click(function () {
    	var ids = new Array();
		$("input[name='ids[]']:checked").each(function(i, o) {
			ids.push($(this).val());
		});
        bootbox.confirm({
            title: "系统提示",
            message: "是否要删除所选用户？",
            callback: function (result) {
                if (result) {
                	console.log(ids);
                    $.ajax({
                    	type:"post",
                    	url:"{:url('del')}",
                    	data:'ids='+ids,
                    	//dataType:"",
                    	error:function(){
                    		return false;
                    	},
                    	success:function(data){
                    		console.log(data.message);
                    		bootbox.alert({  
                                buttons: {  
                                   ok: {label: '确定',className: 'btn-danger'}  
                                },  
                                message: data.message,  
                                callback: function() {  
                                    if(data.flag == 0){
       	                       			location.reload(); 
       	                       		}
                                },  
                                title: "系统提示",  
                            });
                    	}
                    });
                }
            },
            buttons: {
                "cancel": {"label": "取消"},
                "confirm": {
                    "label": "确定",
                    "className": "btn-danger"
                }
            }
        });
    });
</script>
</body>
</html>
